﻿
Dcqtech_Form_Controls.ContentEditer = $.extend({}, Dcqtech_Form_Controls.Default);

Dcqtech_Form_Controls.ContentEditer.setValue = function (id, value, fieldInfo, $root, isFirstSet) {
    $root.find("[dcqtech_data='" + id + "']").val(value);
    ContentEditer_initUEditor(id, function () {
        var editor = DcqtechUeditor[id];
        editor.setContent(decodeURIComponent(value));
    });
};

Dcqtech_Form_Controls.ContentEditer.setDefaultValue = function (id, $root, fieldInfo) {
    var value = fieldInfo.defaultValue;
    if (!value) return;
    Dcqtech_Form_Controls.ContentEditer.setValue(id, value, fieldInfo, $root);
};

Dcqtech_Form_Controls.ContentEditer.setReadonly = function (id, isReadOnly) {
    if (typeof isReadOnly != "boolean") {
        isReadOnly = isReadOnly == "1";
    }
    if (isReadOnly) {
        ContentEditer_setReadonly(id);
    }
};

Dcqtech_Form_Controls.ContentEditer.beforeSave = function (id, obj) {
    var editor = DcqtechUeditor[id];
    obj.value = encodeURIComponent(editor.getContent());
};




var DcqtechUeditor = DcqtechUeditor || {};

function ContentEditer_initUEditor(id, cb) {
    var editor = DcqtechUeditor[id];
    if (editor) {
        if (cb) editor.ready(cb);
        return;
    }
    var editor = UE.getEditor('editor_' + id, {
        toolbars: [
['fullscreen', 'undo', 'redo', '|',
        'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', '|', 'forecolor', 'backcolor', '|',
        'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
        'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|',
        'directionalityltr', 'directionalityrtl', 'indent', '|',
        'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', '|',
            'simpleupload', 'insertimage', 'link', 'unlink', 'attachment'
],
['|', 'inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow', 'insertcol', 'deletecol', 'mergecells', 'mergeright', 'mergedown', 'splittocells', 'splittorows', 'splittocols', 'charts']
        ],

        initialFrameHeight: 500,
        initialFrameWidth: "100%",
        //iframeCssUrl: '/Areas/WorkFlow/Content/UDF_WorkFormDesign/workform.editor.css',
        allowDivTransToP: true,
        imageScaleEnabled: true,
        imagePopup: true,
        enableAutoSave: false
    });

    DcqtechUeditor[id] = editor;
    editor.ready(function () {
        //设置内部编辑宽度 
        //editor.body.style.width = '1000px';
        if (cb) cb();
        //取消本地自动保存
        this.on('showmessage', function (type, m) {
            if (m['content'] == '本地保存成功') {
                return true;
            }
        });

    });
}


Dcqtech_Form_Controls.ContentEditer.setEditEvent = function (id, wdInfo, $root) {
    ContentEditer_initUEditor(id);
};

Dcqtech_Form_Controls.ContentEditer.setViewEvent = function (id, fieldInfo, $root) {
    ContentEditer_setReadonly(id);
}

function ContentEditer_setReadonly(id) {
    ContentEditer_initUEditor(id, function () {
        var editor = DcqtechUeditor[id];
        editor.setDisabled('fullscreen');
        var eitorid = "editor_" + id;
        $("#" + eitorid + " .edui-editor-toolbarboxouter").hide();
        $("#" + eitorid + " .edui-editor-bottomContainer").hide();
    });
}


